package com.hz.ruoyiquality.service.impl;

import com.hz.ruoyiquality.domain.dto.OrderUpdateDTO;
import com.hz.ruoyiquality.mapper.OrderMapper;
import com.hz.ruoyiquality.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 根据是否需要车辆   更新订单状态
     */
    public Integer needVehicle(Integer orderNo){
        return orderMapper.needVehicle(orderNo);
    }

    /**
     * 事务控制，保证两个 SQL 一起执行
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateOrderStatus(OrderUpdateDTO orderUpdateDTO) {
        // 更新质检状态
        int updateQuality = orderMapper.updateOrder(orderUpdateDTO);
        if (updateQuality == 0) {
            throw new RuntimeException("更新质检状态失败");
        }

    }


    @Override
    public void updateRuStorageOrder(OrderUpdateDTO orderUpdateDTO) {
        // 更新
        int updateQuality = orderMapper.updateRuStorageOrder(orderUpdateDTO);
        if (updateQuality == 0) {
            throw new RuntimeException("更新 状态失败");
        }
    }
}
